package model.base;
import java.util.HashMap;

import model.algorithm.Heurictics;
import model.domain.MazeDomainHeuristic;
import model.domain.Puzzle8DomainHeuris;


public class HeuristicsFactory {
	private HashMap<String, HeuristicsCreator> heurist;
	
	public HeuristicsFactory() {								// C'tor
		heurist = new HashMap<String, HeuristicsCreator>();			// defines cases for  domain creators according to the string given
		heurist.put("8Puzzle", new Puzzle8HeurisCreator());
		heurist.put("Maze", new MazeHeurisCreator());
	}
	
	public Heurictics createHeuristics(String HeuName){			// Will be operated by SearchAlgorithmFactory 
		HeuristicsCreator hc = heurist.get(HeuName);			// gets a heuristicsCreator from the HMap
		Heurictics heuristics = null;
		if (hc != null)
			heuristics = hc.create();							// and makes it to create new heuristics
		return heuristics;
	}
	
	
	
	
//////////////////////////////////////////////////////////////////////////
	
	private interface HeuristicsCreator{		//HeuristicsCreator interface 	
		Heurictics create();
	}
	
	private class Puzzle8HeurisCreator implements HeuristicsCreator{		// Sort of heuristicsCreator - specific for puzzle8Domain
		@Override
		public Heurictics create() {
			return new Puzzle8DomainHeuris();						// creates new instance of Puzzle8DomainHeuristic
		}
	}

	private class MazeHeurisCreator implements HeuristicsCreator{			// Sort of heuristicsCreator - specific for MazeDomain
		@Override
		public Heurictics create() {
			return new MazeDomainHeuristic();						// creates new instance of MazeDomainHeuristic
		}
	}
}
